package nc.ui.arap.service;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import nc.ui.ep.dj.DjPanel;
import nc.ui.pub.ClientEnvironment;
import nc.vo.arap.engine.BtnInfoVO;
import nc.vo.arap.engine.FlowInfoVO;
import nc.vo.arap.service.ServiceVO;
import nc.vo.arap.workflow.config.ConfigAgent;
import nc.vo.arap.workflow.config.ConfigCache;
import nc.vo.pub.BusinessException;

public class InitNodeCall extends AbstractCall implements IRemoteCallItem {

	public InitNodeCall(DjPanel panel) {
		super(panel);
	}

	public ServiceVO getServcallVO() {
		callvo = new ServiceVO();
		callvo.setClassname("nc.itf.arap.pub.IConfigurationServicePublic");
		callvo.setMethodname("initNode");
		callvo.setParamtype(new Class[] { String.class, String.class });
		callvo.setParam(new Object[] {getParent().getModuleCode(),parent.getDjSettingParam().getPk_corp()});
		return callvo;
	}

	public void handleResult(Map<String, Object> datas) throws BusinessException {
		List<List<Map<String, ?>>> values = (List<List<Map<String, ?>>>) datas.get(callvo.getCode());

		ConfigCache cache = ((ConfigAgent)ConfigAgent.getInstance()).getCache();
		List<Map<String, ?>> buttons = values.get(0);
		List<Map<String, ?>> flows = values.get(1);
		
		String nodeCode = getParent().getModuleCode();
		
		cache.putButtons(nodeCode, parent.getDjSettingParam().getPk_corp(),(Map<String, BtnInfoVO>) buttons.get(0));
		
		for (Iterator iter = flows.iterator(); iter.hasNext();) {
			Map<String, FlowInfoVO> flow = (Map<String, FlowInfoVO>) iter.next();
			if(flow!=null && flow.size()!=0){
				cache.putFlows(flow.values().iterator().next().getNamespace(), flow);
			}
		}
	}

}
